<?php
	$ListingModelObj = cri('Listing');
	$fieldproperies = $ListingModelObj->fieldProperties;
	$showFields = $ListingModelObj->getFields('group','add');
?>
<?php
	$i = 0;
	foreach($fieldproperies as $field=>$fieldInfo)
	{		
		if(isset($fieldInfo['fieldset_name']))
		{
			if($ListingModelObj->getFieldProperties($field,'type') == 'multipleCheckbox')
			{
				$fieldInfo['div'] = 'checkbox_group';
			}									
			$newFieldproperies[$fieldInfo['fieldset_name']][$i][$field] = $fieldInfo;
			$newFieldproperies[$fieldInfo['fieldset_name']]['fieldsetInfo']['fieldset_id'] = $fieldInfo['fieldset_id'];
			$newFieldproperies[$fieldInfo['fieldset_name']]['fieldsetInfo']['fieldset_label'] = $fieldInfo['fieldset_label'];
			$newFieldproperies[$fieldInfo['fieldset_name']]['fieldsetInfo']['fieldset_show_label'] = $fieldInfo['fieldset_show_label'];
			$i++;
		}	
	}
?>
	
	
<?php 
	if(!isset($this->params['admin']))
	{
		unset($listingDefaultFields['meta_keywords']);
		unset($listingDefaultFields['image']);
		unset($listingDefaultFields['meta_description']);
	}
  
  unset($listingDefaultFields['additional_categories']);
	//code to show default fields.
	echo $form->inputs(am(array('fieldset'=>false),$listingDefaultFields));

	//code to show custom field info starts here
	if(!empty($newFieldproperies))
	{
		foreach($newFieldproperies as $fieldsetName=>$fieldsetFields)
		{
			$fieldsetOtherInfo = $fieldsetFields['fieldsetInfo'];
			unset($fieldsetFields['fieldsetInfo']);
			?>
			<div class = "fieldset <?php echo $fieldsetName?>" id="fieldset_input_<?php echo $fieldsetOtherInfo['fieldset_id']?>">
				<fieldset>
					<legend>
						<?php
						if($fieldsetOtherInfo['fieldset_show_label'] == 1)
						{ 
							echo $fieldsetOtherInfo['fieldset_label'];
						}?>
					</legend>
					<?php
					foreach($fieldsetFields as $fields)
					{	
						foreach($fields as $field=>$fieldInfo)
						{
							if(in_array($field,$showFields))
							{?>
								<div class="custom_field" id="custom_field_<?php echo $fieldInfo['custom_field_id']?>">	
                                  <?php
                                    $fieldType = $ListingModelObj->getFieldProperty($field,'type');
                                    if($fieldType == SCHEMA_TYPE_VIDEO && isset($listingData) && @$listingData['Listing'][$field])
                                    {
                                      $video =  $customFieldDisplay->showVideo(null,$listingData['Listing'][$field]);  
                                      if($video)
                                      {
                                        
                                        $videoDomId = "video_show_".rand(1,100);
                                        $videoWrapperDomId = $videoDomId."_wrapper";
                                        $video = "<div id=\"$videoDomId\" style='display:none'>$video</div>";
                                        $videoHtml = $html->link(__("View current video"),'javascript:void(0)',array("onclick"=>"$('#$videoDomId').toggle()"));
                                        $videoADomId = $videoDomId.'_a';
                                        $videoHtml .= ' | '.$html->link(__("Delete current video"),array("action"=>"deleteVideo",$listingData['Listing']['id'],$field),array("id"=>$videoADomId,'onclick'=>"return false;"));
                                        $msg = __("Are you sure you want to delete this video?");
                                        $js=<<<JS
                                          \$('#$videoADomId').click(function(){
                                              if(confirm("$msg"))
                                              {
                                                \$.get(\$(this).attr('href'));
                                                \$('#$videoWrapperDomId').hide('slow');
                                              }
                                              return false;
                                          })
JS;
                                        $javascript->startup($js);
                                        $videoHtml .= $video;
                                        $fieldInfo['after'] = "<div id='$videoWrapperDomId'>".$videoHtml.'</div>';
                                      }
                                    }
                                 ?>
                                      
                                  <?php echo $form->input($field,$fieldInfo);?>
                                </div>
							<?php
							}
						}
					}?>
				</fieldset>
			</div>
			<?php 
		}
	}	
	//code to show custom field info ends here
  
  //Call hook modifiy form
  $this->listingFormHtml = "";
  callHooks("ListingFormFields",'.+',$this,$form,@$listingData, $showFields);
  echo $this->listingFormHtml;
  unset($this->listingFormHtml);
	?>